<!DOCTYPE html>
<html lang="en">
<header>
    <style>
        a.go-btn {
            background-color: #21ab00;
            padding: 5px 10px;
            border-radius: 8px;
            color: white;
            text-decoration: none;
            font-weight: bold;
        }
        a.go-btn:hover {
            background-color: #7FFF00;
        }
        .page-header {
            display: flex;
            margin: 20px;
        }
        .page-header h1 {
            color: #263184
        }
        .page-header a.clear-btn {
            position: absolute;
            right: 95px;
            top: 40px;
            background-color: #263184;
            padding: 5px 10px;
            border-radius: 8px;
            color: white;
            text-decoration: none;
            font-weight: bold;
        }
        .page-header a.clear-btn:hover {
            background-color: #1D58A4;
        }
        .page-header a.refresh-btn {
            position: absolute;
            right: 255px;
            top: 40px;
            background-color: #263184;
            padding: 5px 10px;
            border-radius: 8px;
            color: white;
            text-decoration: none;
            font-weight: bold;
        }
        .page-header a.refresh-btn:hover {
            background-color: #1D58A4;
        }
        .page-header a.go-btn {
            position: absolute;
            right: 40px;
            top: 40px;
        }
        .page-header .go-msg {
            position: absolute;
            right: 40px;
            top: 80px;
            color: grey;
        }
        table, th, td {
            border: 1px solid #F0F1F2;
            border-collapse: collapse;
            font-size: 14px;
        }
        table {
            width: calc(100% - 80px);
            margin: 20px 40px;
            color: #30353B;
        }
        th, td {
            padding: 10px;
            text-align: start;
            min-width: 200px;
        }
        table thead tr {
            background-color: #263184;
            color: white;
            text-transform: uppercase;
        }
        .metrics-items {
            margin: 20px 40px;
            display: flex;
            justify-content: space-between;
        }
        .metrics-items .metrics-item {
            background-color: #A573DF;
            width: 100%;
            height: 70px;
            color: white;
            padding: 15px;
            border-radius: 8px;
            box-sizing: border-box;
        }
        .metrics-items .metrics-item.defcon1 {
            background-color: #C60007;
        }
        .metrics-items .metrics-item.critical {
            background-color: #F5555B;
        }
        .metrics-items .metrics-item.high {
            background-color: #F59E56;
        }
        .metrics-items .metrics-item:not(:last-child) {
            margin-right: 10px;
        }
        .metrics-items .metrics-item .metric-title {
            font-size: 10px;
            font-weight: bold;
        }
        .metrics-items .metrics-item .metric-count {
            font-size: 24px;
            padding-top: 5px;
        }
        .modal-outer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(48, 53, 59, 0.8);
        }
        .modal-outer .modal-container {
            position: absolute;
            background-color: white;
            z-index: 2;
            padding: 20px;
            overflow-y: auto;
            top: 15%;
            left: calc(50% - 400px / 2);
            width: 400px;
            height: 230px;
        }
        .modal-outer .modal-container .modal-title {
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 30px;
        }
        .modal-outer .modal-container .btn-container {
            position: absolute;
            right: 40px;
            bottom: 40px;
        }
        .modal-outer .modal-container .btn-container .go-btn {
            margin-left: 10px;
        }
        td.tooltip {
            position: relative;
            display: inline-block;
        }

        td.tooltip .tooltiptext {
            visibility: hidden;
            width: 150px;
            background-color: #626adb;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px 0;

            /* Position the tooltip */
            position: absolute;
            z-index: 1;
        }

        td.tooltip:hover .tooltiptext {
            visibility: visible;
        }

        /* Style tab links */
        .tablink {
            background-color: #555;
            color: white;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            font-size: 17px;
            width: 50%;
        }

        .tablink:hover {
            background-color: #777;
        }

        /* Style the tab content (and add height:100% for full page content) */
        .tabcontent {
            color: orange;
            display: none;
            padding: 100px 20px;
            height: 100%;
        }
    </style>
</header>
<body>
<div class="page-header">
    <img src="https://www.portshift.io/wp-content/uploads/2018/11/platform-left-image.png" alt="Portshift" width="60" height="60">
    <h1>KUBEI Runtime Vulnerabilities Analyzer</h1>
    <a class="refresh-btn" href="#" onclick="window.location.reload();">REFRESH</a>
    <a class="clear-btn" href="/clear">CLEAR RESULTS</a>
    <a class="go-btn" href="/go/verify">GO</a>
    {{if .ShowGoMsg}}
        <div class="go-msg"> Started scanning {{.LastScannedNamespace}}</div>
    {{end}}
</div>

<button class="tablink" onclick="openPage('Vulnerability', this, '#c40b0b')" id="defaultOpen">Vulnerability scanning</button>
<button class="tablink" onclick="openPage('Dockerfile', this, '#141eac')">CIS Docker benchmark</button>

<div id="Vulnerability" class="tabcontent">
    <div class="metrics-items">
        <div class="metrics-item">
            <div class="metric-title">Total Vulnerabilities</div>
            <div class="metric-count">{{ .Vulnerabilities.Total }}</div>
        </div>
        <div class="metrics-item defcon1">
            <div class="metric-title">Total Defcon1</div>
            <div class="metric-count">{{ .Vulnerabilities.TotalDefcon1 }}</div>
        </div>
        <div class="metrics-item critical">
            <div class="metric-title">Total Critical</div>
            <div class="metric-count">{{ .Vulnerabilities.TotalCritical }}</div>
        </div>
        <div class="metrics-item high">
            <div class="metric-title">Total High</div>
            <div class="metric-count">{{ .Vulnerabilities.TotalHigh }}</div>
        </div>
    </div>
    <table>
        <thead>
        <tr>
            <th>Pod Name</th>
            <th>Container Name</th>
            <th>Namespace</th>
            <th>Succeeded</th>
            <th>Name</th>
            <th>Severity</th>
            <th>Image Name</th>
            <th>Found In</th>
        </tr>
        </thead>
        <tbody>
        {{ range .Vulnerabilities.Vulnerabilities}}
            <tr>
                <td>{{ .Pod }}</td>
                <td>{{ .Container }}</td>
                <td>{{ .Namespace }}</td>
                {{if .Succeeded}}
                    <td>{{ .Succeeded }}</td>
                {{ else}}
                    <td class="tooltip">{{ .Succeeded }}
                        <span class="tooltiptext">Scan has failed! See scanner pod logs for more info.</span>
                    </td>
                {{ end}}
                {{if .Succeeded}}
                    <td><a href={{ .Vulnerability.Link }}>{{ .Vulnerability.Name }}</a></td>
                    <td>{{ .Vulnerability.Severity }}</td>
                {{ else}}
                    <td></td>
                    <td></td>
                {{ end}}
                <td>{{ .Image }}</td>
                {{if .Succeeded}}
                    <td>{{ .Vulnerability.Package }}:{{ .Vulnerability.PackageVersion }}</td>
                {{ else}}
                    <td></td>
                {{ end}}
            </tr>
        {{ end}}
        </tbody>
    </table>
</div>

<div id="Dockerfile" class="tabcontent">
    <div class="metrics-items">
        <div class="metrics-item">
            <div class="metric-title">Total Dockerfile Vulnerabilities</div>
            <div class="metric-count">{{ .DockerfileVulnerabilities.Total }}</div>
        </div>
        <div class="metrics-item defcon1">
            <div class="metric-title">Total Fatal</div>
            <div class="metric-count">{{ .DockerfileVulnerabilities.TotalFatal }}</div>
        </div>
        <div class="metrics-item critical">
            <div class="metric-title">Total Warn</div>
            <div class="metric-count">{{ .DockerfileVulnerabilities.TotalWarn }}</div>
        </div>
        <div class="metrics-item high">
            <div class="metric-title">Total Info</div>
            <div class="metric-count">{{ .DockerfileVulnerabilities.TotalInfo }}</div>
        </div>
    </div>
    <table>
        <thead>
        <tr>
            <th>Pod Name</th>
            <th>Container Name</th>
            <th>Image Name</th>
            <th>Namespace</th>
            <th>Succeeded</th>
            <th>Title</th>
            <th>Level</th>
            <th>Description</th>
        </tr>
        </thead>
        <tbody>
        {{ range .DockerfileVulnerabilities.DockerfileVulnerabilities}}
            <tr>
                <td>{{ .Pod }}</td>
                <td>{{ .Container }}</td>
                <td>{{ .Image }}</td>
                <td>{{ .Namespace }}</td>
                {{if .Succeeded}}
                    <td>{{ .Succeeded }}</td>
                    <td>{{ .DockerfileVulnerability.Code }}:{{ .DockerfileVulnerability.Title }}</td>
                    <td>{{ .DockerfileVulnerability.Level }}</td>
                    <td>{{ .DockerfileVulnerability.Description }}</td>
                {{ else}}
                    <td class="tooltip">{{ .Succeeded }}
                        <span class="tooltiptext">Scan has failed! See scanner pod logs for more info.</span>
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                {{ end}}
            </tr>
        {{ end}}
        </tbody>
    </table>
</div>

{{if .ShowGoWarning}}
<div class="modal-outer">
    <div class="modal-container">
        <div class="modal-title">Are you sure?</div>
        <div>Are you sure you want to execute a new scan? previous results will be lost</div>
        <div class="btn-container">
            <a class="cancel-btn" href="/go/cancel">Cancel</a>
            <a class="go-btn" href="/go/run">GO</a>
        </div>
    </div>
</div>
{{ end}}

<script>
    function openPage(pageName,elmnt,color) {
        var i, tabcontent, tablinks;
        tabcontent = document.getElementsByClassName("tabcontent");
        for (i = 0; i < tabcontent.length; i++) {
            tabcontent[i].style.display = "none";
        }
        tablinks = document.getElementsByClassName("tablink");
        for (i = 0; i < tablinks.length; i++) {
            tablinks[i].style.backgroundColor = "";
        }
        document.getElementById(pageName).style.display = "block";
        elmnt.style.backgroundColor = color;
    }

    // Get the element with id="defaultOpen" and click on it
    document.getElementById("defaultOpen").click();
</script>

</body>
</html>
